package cn.gs.web;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import cn.gs.domain.Customer;
import cn.gs.domain.Visit;
import cn.gs.service.SelectVisitService;

@Component(value = "selectVisitAction")
@Scope("prototype")
public class SelectVisitAction extends ActionSupport implements ModelDriven<Visit> {
	private Visit visit = new Visit();
	private Customer customer = new Customer();
	@Resource(name = "selectVisitService")
	private SelectVisitService selectVisitService;
	private List<Visit> list;
	private String pageCount;
	private String page;
	private String pCount;
	private String cname;

	public String allsel() {
		if (page == null) {
			page = "1";
		}
		customer.setCust_name(cname);		
		System.out.println("客户姓名：" + customer.getCust_name() + "didian:" + visit.getVisit_addr());
		int i = Integer.valueOf(page);
		try {
			list = selectVisitService.selectVisit(customer.getCust_name(), visit.getVisit_addr(), i);
			List l=selectVisitService.selectPageCount(customer.getCust_name(),visit.getVisit_addr());
			pageCount=String.valueOf(l.get(0));
			int a=Integer.valueOf(pageCount) ;
			int b=0;
			if(a%3==0) {
				b=a/3;
			}else {
				b=a/3+1;
			}
			pCount =String.valueOf(b);
			ActionContext.getContext().put("pCount",pCount);
			ActionContext.getContext().put("pageCount",pageCount);
			ActionContext.getContext().put("list", list);
			return "selSuc";
		} catch (Exception e) {
			return "selDef";
		}
	}

	@Override
	public Visit getModel() {
		// TODO Auto-generated method stub
		return visit;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public SelectVisitService getSelectVisitService() {
		return selectVisitService;
	}

	public void setSelectVisitService(SelectVisitService selectVisitService) {
		this.selectVisitService = selectVisitService;
	}

	public List<Visit> getList() {
		return list;
	}

	public void setList(List<Visit> list) {
		this.list = list;
	}

	public String getPageCount() {
		return pageCount;
	}

	public void setPageCount(String pageCount) {
		this.pageCount = pageCount;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public String getpCount() {
		return pCount;
	}

	public void setpCount(String pCount) {
		this.pCount = pCount;
	}

	public String getCname() {
		return cname;
	}

	public void setCname(String cname) {
		this.cname = cname;
	}

}
